# -*- coding: utf-8 -*-
# @Time    : 2022/1/25 12:47
# @Author  : Mr.Ye
# @Email   : a3289748713@163.com
# @File    : test2.py
# @Software: PyCharm
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import os
from datetime import datetime

app = Flask(__name__)

MYSQL_HOST = os.getenv('MYSQL_HOST') or '127.0.0.1'
MYSQL_USER = os.getenv('MYSQL_USER') or 'root'
MYSQL_PASSWORD = os.getenv('MYSQL_PASSWORD') or 'sy_root'
MYSQL_DATABASE = os.getenv('MYSQL_DATABASE') or 'video'
SECRET_KEY = os.getenv('SECRET_KEY') or 'aaaa'

SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://{user}:{password}@{host}:3306/{name}'.format(user=MYSQL_USER,
                                                                                        password=MYSQL_PASSWORD,
                                                                                        name=MYSQL_DATABASE,
                                                                                        host=MYSQL_HOST)
print(SQLALCHEMY_DATABASE_URI)
app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI  # 配置数据URI
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_ECHO'] = True
app.config["SECRET_KEY"] = SECRET_KEY
# 将配置后的app绑定SQL
app.debug = True
db = SQLAlchemy(app)
